<?php

echo "<?php\n";
?>
namespace <?= $generator->ns ?>;
use Yii;
use common\models\BaseModel;


class <?= $className ?> extends BaseModel
{

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '<?= $generator->generateTableName($tableName) ?>';
    }


    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [<?= empty($rules) ? '' : ("\n            " . implode(",\n            ", $rules) . ",\n        ") ?>];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
<?php foreach ($labels as $name => $label): ?>
            <?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
<?php endforeach; ?>
        ];
    }

	/*
		* data list 
		* @param whereArr 条件
		* @param params 基本参数 包含 field order page limit
		* @param extends  扩展信息 一些相关的信息
		* return array
	*/
	public static function dataList($whereArr, $params, $extends = array())
	{
		$model  = self::find();
		$where  = isset($whereArr['where']) ? $whereArr['where'] : [];
		$whereAnd = isset($whereArr['and']) ? $whereArr['and'] : [];
		$models = self::queryFormart($model, $where, $params, $whereAnd);
		$model  = $models['model'];
		self::$totalNums = $models['totalNums'];
		self::$query = $models['query'];

		$data  = $model->asarray()->all();
		if(empty($data)) return array();
		if(empty($extends)) return $data;
		foreach($extends as $ext)
		{
			## 获取需要的扩展信息

		}
		return $data;				
	}


	public static function getOne($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->one();
	}


	public static function getAll($where, $field = ['*'])
	{
		return self::find()->select($field)->where($where)->all();
	}

}


